﻿if (typeof (Seq) == 'undefined') Seq = new Object();

Seq.Viewport = Class.create({

	initialize: function() {
		this.reset();
	},

	reset: function() {
		this.headersize = 100;
		this.basex = 0;
		this.basey = 0;
		this.beatwidth = 80;
		this.multiplier = 100;
		this.zoom = 100;
		this.duration = 4 * 4 * 100;
		this.quant = 8;
		this.quantsnap = 1;
		this.numerator = 4;
		this.denominator = 4;
		this.maxvalue = 128;
		this.keyheight = 20;
		this.height = 200;
	},

	BeatWidth: function() {
		return this.TtoX(this.multiplier * 2) - this.TtoX(this.multiplier * 1);
	},

	SnapT: function(t) {
		t /= this.multiplier;
		t *= this.quant;
		t = Math.floor(t);
		t /= this.quant;
		t *= this.multiplier;
		return t;
	},

	XtoT: function(x) {
		x -= this.basex;
		x -= this.headersize;
		x /= this.beatwidth;
		x *= this.multiplier;
		x /= this.zoom / 100;
		if (x < 0) x = 0;
		if (x > this.duration) x = this.duration;
		return x;
	},

	TtoX: function(t) {
		if (t < 0) t = 0;
		if (t > this.duration) t = this.duration;
		t /= (100 / this.zoom);
		t /= this.multiplier;
		t *= this.beatwidth;
		t += this.headersize;
		t += this.basex;
		return t;
	},

	YtoK: function(y) {
		y /= this.keyheight;
		y = Math.floor(y);
		y = 127 - y;
		return y;
	},

	KtoY: function(k) {
		k = 127 - k;
		k = Math.floor(k) * this.keyheight;
		return k;
	},

	YtoV: function(y) {
		y -= this.basey;
		y = this.height - y;
		y = (this.maxvalue * y) / this.height;
		return y;
	},

	VtoY: function(v) {
		v = (this.height * v) / this.maxvalue;
		v = this.height - v;
		v += this.basey;
		return v;
	}

});


Seq.CurveInterpolator = Class.create({

	initialize: function() {
		this.points = [];
	},

	points: [],

	prepare: function() {
		// sort points
	},

	getKey: function(t) {
		return points[0];
	},

	getValue: function(t) {
		return 64 + ((t * 100) % 32);
	}
});



